//
//  YFLcommentTableViewCell.m
//  Music
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YFLcommentTableViewCell.h"

@implementation YFLcommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.photoImageView =[[UIImageView alloc]init];
       // self.photoImageView.backgroundColor =[UIColor orangeColor];
        self.photoImageView.layer.cornerRadius = 30;
        self.photoImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.photoImageView];
        
        self.nameLabel =[[UILabel alloc]init];
       // self.nameLabel.backgroundColor =[UIColor redColor];
        [self.contentView addSubview:self.nameLabel];
        
        self.commentLabel =[[UILabel alloc]init];
      //  self.commentLabel.backgroundColor =[UIColor purpleColor];
        self.commentLabel.font =[UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.commentLabel];
        
        self.timeLabel =[[UILabel alloc]init];
       // self.timeLabel.backgroundColor =[UIColor yellowColor];
        [self.contentView addSubview:self.timeLabel];

        self.floorLabel =[[UILabel alloc]init];
        self.floorLabel.textColor = [UIColor whiteColor];
        self.floorLabel.textAlignment = 1;
        self.floorLabel.adjustsFontSizeToFitWidth = YES;
        self.floorLabel.backgroundColor =[UIColor greenColor];
        [self.contentView addSubview:self.floorLabel];
        
    
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.photoImageView.frame = CGRectMake(10, 10, 60, 60);
    
    self.floorLabel.frame = CGRectMake(self.photoImageView.frame.origin.x, self.photoImageView.frame.size.height+self.photoImageView.frame.origin.y, self.photoImageView.frame.size.width, 20);
    
    self.nameLabel.frame = CGRectMake(self.photoImageView.frame.origin.x+self.photoImageView.frame.size.width+10, self.photoImageView.frame.origin.y, Screenwidth/2, 20);
    
    self.timeLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y+self.nameLabel.frame.size.height+5, self.nameLabel.frame.size.width, self.nameLabel.frame.size.height);
    
    self.commentLabel.frame = CGRectMake(self.timeLabel.frame.origin.x, self.timeLabel.frame.size.height+self.timeLabel.frame.origin.y+5, Screenwidth/2+80, self.timeLabel.frame.size.height*2);
    
    
}
-(void)setCommentModel:(YFLcommentModel *)commentModel
{
    if (_commentModel != commentModel) {
        _commentModel = commentModel;
    }
    
    [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:commentModel.pic] placeholderImage:[UIImage imageNamed:@"占.jpg"]];
    
   self.floorLabel.text =[NSString stringWithFormat:@"第%@楼", commentModel.storey.description];
    self.nameLabel.text = commentModel.nick_name;
    self.commentLabel.text = commentModel.content;
    
    
    NSString *time = commentModel.created_time;
    NSInteger num = [time integerValue]/1000;//（重点）//例如:1464516173377
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSDate*confromTimesp = [NSDate dateWithTimeIntervalSince1970:num];
   NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    self.timeLabel.text = confromTimespStr;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
